package com.woniu.service.impl;

import com.woniu.entity.Goods;
import com.woniu.mapper.GoodsMapper;
import com.woniu.service.GoodsService;
import com.woniu.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class GoodsServiceImpl implements GoodsService {
    SqlSession sqlSession = MyBatisUtil.getSqlSession();
    GoodsMapper mapper = sqlSession.getMapper(GoodsMapper.class);
    @Override
    public void insertGoods(Goods goods) {
       mapper.insertGoods(goods);
       sqlSession.commit();
       sqlSession.close();
    }

    @Override
    public Goods selectGoods(Integer pid, Integer uid) {
        Goods goods = mapper.selectGoodsById(pid,uid);
        return goods;
    }

    @Override
    public void updateGoods(Integer stock,Integer pid,Integer uid ) {
        mapper.updateGoods(stock,pid,uid);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public List<Goods> selectGoodsAll(Integer uid) {
        List<Goods> goods = mapper.selectGoodsAll(uid);
        return goods;
    }

    @Override
    public void deleteGoodsByUId(Integer uid) {
        mapper.deleteGoodsByUid(uid);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void deleteGoodsByUidPid(Integer uid, Integer pid) {
        mapper.deleteGoodsByPidUId(uid,pid);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void deleteGoodsByMerchantId(Integer merchant_id) {
        mapper.deleteGoodsByMerchantId(merchant_id);
        sqlSession.commit();
        sqlSession.close();
    }



}
